/*
 * @Author: 谢子健 1075010289@qq.com
 * @Date: 2024-09-21 23:27:11
 * @LastEditors: 谢子健 1075010289@qq.com
 * @LastEditTime: 2024-10-03 22:01:37
 * @FilePath: \ilink-vue-frontend\src\api\study\studySquare.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// src/api/data/studySquare.ts

import { api } from '../api';

/**
 * 获取课程详情
 * @param id 课程 ID
 * @returns 课程详情
 */

/**
 * 获取收藏列表
 * @returns 收藏项数组
 */
/**
 * 添加到收藏
 * @param treeId 技能树 ID
 * @returns 成功消息
 */

// 添加到收藏
export const addFavoriteTree = async (treeId: string): Promise<string> => {
  try {
    const response = await api.post('/java/teacher/study_tree_json/add_favorite_tree', {
      treeId,
    });

    return response.data;
  }
  catch (error) {
    console.error('Error adding to favorite:', error);
    throw error;
  }
};

// 获取技能树标签
export const getCommonStudyTreeTags = async () => {
  try {
    const response = await api.get('/java/teacher/study_tree_json/getCommonStudyTreeTags');
    return response.data
  }
  catch (error) {
    console.error('获取资源信息失败', error)
    throw error
  }
}

// 获取课程标签
export const getCommonCourseTags = async () => {
  try {
    const response = await api.get('/java/ground/study/course/get_common_course_tags');
    return response.data
  }
  catch (error) {
    console.error('获取资源信息失败', error)
    throw error
  }
}

// 获取技能树JSON
export const getStudyTreeJsonApi = async (params: any) => {
  try {
    const response = await api.get('/java/ground/study/course/get_course_information_by_id', {
      params,
    });
    return response.data
  }

  catch (error) {
    console.error('获取资源信息失败', error)
    throw error
  }
}
// 获取实训标签
export const getCommonPracticeTags = async () => {
  try {
    const response = await api.get('/java/ground/study/practice/tags');
    return response.data;
  }
  catch (error) {
    console.error('获取实训标签失败', error);
    throw error;
  }
};

// 获取实训数据
export const getPracticeMetadata = async (params: any) => {
  try {
    const response = await api.get('/java/ground/study/practice/list', {
      params,
    });
    return response.data;
  }
  catch (error) {
    console.error('获取实训数据失败', error);
    throw error;
  }
};
